﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WT7
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            //wTDV_TAB_WELL_ND_MONTH_DATADomainDataSource.Load();
        }

        private void HyperlinkButton_UpdateStates()
        {
            foreach (UIElement child in LinksStackPanel.Children)
            {
                HyperlinkButton hb = child as HyperlinkButton;
                if (hb != null)
                {
                    if (tabControl1.SelectedIndex == Int32.Parse(hb.Tag.ToString()))
                    {
                        VisualStateManager.GoToState(hb, "ActiveLink", true);
                    }
                    else
                    {
                        VisualStateManager.GoToState(hb, "InactiveLink", true);
                    }
                }
            }
        }

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tabControl1.SelectedIndex = Int32.Parse((sender as Control).Tag.ToString());
                HyperlinkButton_UpdateStates();
            }
            catch (Exception err)
            {
                ChildWindow errorWin = new ErrorWindow(err);
                errorWin.Show();
            }
            
        }

        private void wTDV_TAB_WELL_ND_MONTH_DATADomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {
            //wTDV_TAB_WELL_ND_MONTH_DATADomainDataSource.AutoLoad = false;
            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void wTDV_TAB_WELLDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void wTDV_TAB_WELL_ND_MONTH_DATADomainDataSource1_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void wTDV_TAB_WELL_YEARDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }


        /*
         h_ttp://www.c-sharpcorner.com/Blogs/6681/datagrid-loadingrow-event-in-silverlight.aspx
         
      void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e) 
        { 
            DataGridRow row = e.Row; 
            foreach (DataGridColumn col in dataGrid1.Columns) 
            { 
                FrameworkElement cell = col.GetCellContent(e.Row); 
                cell.MouseLeftButtonDown += new MouseButtonEventHandler(this.DataGridCell_OnMouseLeftButtonUp); 
            } 
        }            
         */
    }
}